﻿using System;

namespace Sencha.Serialization.Exceptions
{
	[Serializable]
	public class DataContractException : System.Runtime.Serialization.SerializationException
	{
		public int Code { get; set; }

		internal DataContractException(string message, ErrorCode errorCode) : base(message) { }
		internal DataContractException(string message, ErrorCode errorCode, Exception innerException) : base(message, innerException) { }
		internal DataContractException(string message, Exception innerException) : base(message, innerException) { Code = (int)ErrorCode.GenericDataContractException; }
		internal DataContractException(string message) : base(message) { Code = (int)ErrorCode.GenericDataContractException; }

		protected DataContractException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
			: base(info, context)
		{
			this.Code = info.GetInt32("Code");
		}

		[System.Security.SecurityCritical]
		public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
		{
			info.AddValue("Code", this.Code);
			base.GetObjectData(info, context);
		}
	}
}
